import time

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Edge()
driver.implicitly_wait(10)

driver.get("https://www.baidu.com/")

# 有时间我们需要获取窗口的属性和相应的信息，并对窗口进行控制
print(driver.get_window_size())
# 改变窗口大小
driver.set_window_size(550, 500)
time.sleep(5)
# 获取窗口标题
print(driver.title)
# 获取当前窗口URL地址
print(driver.current_url)

# 截屏保存为图片文件
driver.get_screenshot_as_file('1.png')

# 我们可以通过 desired_capabilities 参数，指定以手机模式打开Edge浏览器
mobile_emulation = { "deviceName": "iPhone 16 Pro Max" }
edge_options = webdriver.EdgeOptions()
edge_options.add_experimental_option("mobileEmulation", mobile_emulation)
driver = webdriver.Edge(options=edge_options)
driver.get('http://www.baidu.com')
time.sleep(5)
driver.quit()

#上传文件
web = webdriver.Edge()
web.get("https://tinypng.com/")
# 先定位到上传文件的 input 元素
ele = web.find_element(By.CSS_SELECTOR, 'input[type=file]')
# 再调用 WebElement 对象的 send_keys 方法
ele.send_keys('./1.png')

